#include<iostream>
#include<algorithm>

using namespace std;

const int N = 110;
const int M = 10010;
int a[N][N];
bool vi[N];
bool vj[N];

struct edge {
    int i, j, v;
} e[M];

bool cmp(edge a, edge b) {
    return a.v > b.v;
}

int main() {
    int n, m;
    cin >> n >> m;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
            e[cnt++] = {i, j, a[i][j]};
        }
    }
    long long ans = 0;
    sort(e, e + cnt, cmp);

    for (int k = 0; k < cnt; ++k) {
        int i = e[k].i, j = e[k].j, v = e[k].v;
        if ( !vi[i] && !vj[j] ) {
            ans += v;
            vi[i] = vj[j] = 1;
        }
    }
    cout << ans << endl;
    return 0;
}